home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.awt.Event;
- import java.awt.TextComponent;
- import java.io.IOException;
- import symantec.itools.db.pro.ProjBinder;
- import symantec.itools.db.pro.ProjLink;
- import symantec.itools.db.pro.RelationView;
- import symantec.itools.db.pro.RelationViewMetaData;
- import symjava.sql.SQLException;
-
- public class TextArea extends java.awt.TextArea implements ProjLink {
- private ProjBinder m_ProjBinder;
- private boolean m_DynamicUpdate = false;
- private boolean m_DynamicUpdateOverride = true;
- private boolean m_BinderDetermines = true;
- private String m_BinderData = new String();
- private String m_ScreenData = new String();
- private int m_treatBlankAs;
-
- public TextArea() {
- }
-
- public TextArea(int rows, int cols) {
- super(rows, cols);
- }
-
- public TextArea(String text) {
- super(text);
- }
-
- public TextArea(String text, int rows, int cols) {
- super(text, rows, cols);
- }
-
- public void init(ProjBinder binder) {
- this.m_ProjBinder = binder;
- this.setEditable(this.m_ProjBinder);
- }
-
- public void setTreatBlankAs(String blank) {
- if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
- this.m_treatBlankAs = 0;
- } else if ((new String(blank)).toUpperCase().equals("NULL")) {
- this.m_treatBlankAs = 1;
- } else {
- if ((new String(blank)).toUpperCase().equals("EMPTY")) {
- this.m_treatBlankAs = 2;
- }
-
- }
- }
-
- public void setBinding(RelationView relView, String projection) {
- int projectionNumber = 0;
- int columnType = 0;
-
- try {
- RelationViewMetaData rvmd = relView.getMetaData();
- projectionNumber = relView.findProjByName(projection);
- columnType = rvmd.getColumnType(projectionNumber);
- if (columnType == 91 || columnType == 92 || columnType == 93) {
- this.m_DynamicUpdateOverride = false;
- }
-
- relView.bindProj(projectionNumber, this);
- } catch (SQLException Ex) {
- this.raiseException("SQLException from setBinding: " + ((Throwable)Ex).getMessage());
- }
- }
-
- public void setDynamicUpdate(boolean update) {
- this.m_DynamicUpdate = update;
- }
-
- public void notifyDataChange(ProjBinder binder) {
- if (binder != null) {
- this.m_ProjBinder = binder;
-
- try {
- if (binder.getRelationView().getCurrentRecordState() != 105) {
- if (binder.isReadable() && !binder.isNull()) {
- this.m_BinderData = binder.getStringValue();
- } else {
- this.m_BinderData = "";
- }
- } else {
- this.m_BinderData = "";
- }
- } catch (SQLException Ex) {
- this.raiseException("SQLException from TextArea.notifyDataChange: " + ((Throwable)Ex).getMessage());
- } catch (IOException Ex) {
- this.raiseException("IOException from TextArea.notifyDataChange: " + ((Throwable)Ex).getMessage());
- }
-
- if (this.m_BinderData == null) {
- this.m_BinderData = new String();
- }
-
- this.m_ScreenData = ((TextComponent)this).getText();
- if (!this.m_BinderData.equals(this.m_ScreenData)) {
- this.m_ScreenData = this.m_BinderData;
- ((TextComponent)this).setText(this.m_ScreenData);
- }
-
- if (this.m_BinderDetermines) {
- this.setEditable(this.m_ProjBinder);
- }
-
- }
- }
-
- public boolean lostFocus(Event evt, Object what) {
- try {
- this.notifySetData(this.m_ProjBinder);
- } catch (SQLException Ex) {
- this.raiseException("SQLException from TextArea.notifySetData: " + ((Throwable)Ex).getMessage());
- }
-
- return super.lostFocus(evt, what);
- }
-
- boolean notifyInputChanged(String input) {
- if (!this.m_ScreenData.equals(input)) {
- this.m_ScreenData = input;
- }
-
- if (!this.m_BinderData.equals(this.m_ScreenData)) {
- this.m_BinderData = this.m_ScreenData;
-
- try {
- if (this.m_ProjBinder != null && this.m_ProjBinder.isWritable()) {
- this.m_ProjBinder.setValueFromString(this.m_ScreenData, 0, this.m_treatBlankAs);
- }
- } catch (SQLException Ex) {
- this.raiseException("SQLException from TextArea.notifyInputChange.setString: " + ((Throwable)Ex).getMessage());
- return false;
- } catch (IOException Ex) {
- this.raiseException("IOException from TextArea.notifyInputChange.setString: " + ((Throwable)Ex).getMessage());
- return false;
- }
- }
-
- return true;
- }
-
- public boolean notifySetData(ProjBinder binder) throws SQLException {
- return this.notifyInputChanged(((TextComponent)this).getText());
- }
-
- public boolean handleEvent(Event evt) {
- if (this.m_DynamicUpdate && this.m_DynamicUpdateOverride) {
- try {
- this.notifySetData(this.m_ProjBinder);
- } catch (SQLException Ex) {
- this.raiseException("SQLException from TextArea.notifySetData: " + ((Throwable)Ex).getMessage());
- }
- }
-
- return super.handleEvent(evt);
- }
-
- void setEditable(ProjBinder binder) {
- boolean isWritable = false;
-
- try {
- if (binder != null) {
- RelationView rv = binder.getRelationView();
- if (rv != null && rv.getCurrentRecordState() != 105) {
- isWritable = binder.isWritable();
- }
- }
- } catch (SQLException Ex) {
- this.raiseException("SQLException from setEditable: " + ((Throwable)Ex).getMessage());
- }
-
- super.setEditable(isWritable);
- }
-
- public void setEditable(boolean value) {
- this.m_BinderDetermines = value;
- super.setEditable(value);
- }
-
- void raiseException(String text) {
- System.out.println(text);
- }
- }
-